;(function($){
	var slider = function(){	
		var ul;
		var timer;
		var spans;
		var page=0;
		var right;
		var left;
		var initData = function(){
			ul.append($('.slider ul li:eq(0)').clone());
			play();
		}
		var play = function(){
			timer = setInterval(function(){
				ul.stop(true,false).animate({"left":"-=1000px"},1000,
					function(){
						if (parseInt(ul.css("left"))<=-6000) {
						ul.css("left","0px");
						} 
						page=(page+1>=7)?0:(page+1);
						$(".nav span").removeClass('active');
						$(".nav span:eq("+(page==6?0:page)+")").addClass('active');
					});
			},2000);
		}
		var showPage = function(){
			$(".nav span").removeClass('active');
			$(".nav span:eq("+(page==6?0:page)+")").addClass('active');
		}
		var nextPage = function(){
			clearInterval(timer);
			//page=page+1==6?1:(page+1);
			//用户在page=0；
			var pos = (page+1)*(-1000);
			ul.stop(true,false).animate({"left":pos+"px"},500,function(){
				page=page+1==6?0:(page+1);
				showPage();
				if (pos==(-6000)) {
					ul.css("left","0px");
				}
			});	
		}
		var loadEvent = function(){
			spans.hover(function(){
				var pos = parseInt($(this).attr("lang"))*-1000;
				clearInterval(timer);
				ul.stop(true,false).animate({"left":pos+"px"},500);
			},function(){
				play();
			});
			right.bind("click",nextPage).bind("mouseout",function(){
				play();
			});			
		}
		return {
			init:function(){
				ul = $(".slider ul");
				spans=$(".nav span");
				right=$(".right");
				left=$(".left");
				initData();
				loadEvent();
			}
		}
	}();
	slider.init();
})(jQuery);
